home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Commodore Free 27
/
Commodore_Free_Issue_27_2009_Commodore_Computer_Club.d64
/
beginning 12-2
< prev
next >
Wrap
Text File
|
2023-02-26
|
11KB
|
375 lines
..
In the Beginning Part 12
Lord Ronin from Q-Link
CONTINUED FROM 12-1
Remember that when we discussed the
Input and the Read stuff, there
wasn't any way to get back or
retrieve the inputted information? OK
we never tried in the first place.
The Commodore users guide is the one
that brings up that subject. Well
type in the following, while you
still have the above program in
memory.
FOR A= 1 TO 5: ?B(A);:NEXT
The reason that I asked you to type
in the amount of numbers as 5 and
those specific numbers. Simply is to
illustrate the point of this line.
You will see on the screen...
125 167 189 167 158
The numbers that you typed in for
this example. See they are stored.
Now try out the programme again and
use your own amount and numbers. Then
adjust the line above. Note it isn't
a line number, just something you can
type in on the screen. Alter the 1 to
what ever you chose for the amount.
Then see what happens.
Welcome now to DIMARRAYS. Well they
say Dimension on page 98. But I am
cutting to the chase here. Because as
soon as you tried more than 10
numbers in the above example you got
an error. Probably said "DIMENSION
ERROR". Makes you wonder what sci-fi
movie you entered. You can only have
11 <0 to 10> elements in a one
dimensional array. OK add the
following to the programme.
5 dim b(100)
You just told the C= that you will
have a maximum of 100 things, or
elements in the array. Can be bigger,
I am not going to say how big at this
time. But it is BIG. Better to make
several different DimArrays than one
gigantic one. OK I'll confess the
maximum that you can put in a
DimArray is <hold onto your hats>
32767. If you do, your program is
bulky and will be very slow.
OK then lets run that program with
the new line 5. Then we are going to
change it to...
5<press return>
Right that kills the line
completely. Have to do that to enter
this one.
15 dim b(x)
Now what ever x is will be the
number of elements in the dim array.
Note here is that once an array has
been <dim>ensioned. It can not be
redone in another part of the
programme. However you can have more
than one dim array in a programme and
even on the same line. Following is
just an example, NOT a line to type
in!
10 dim c(20),d(50),e(40)
Soon we are going to type in a new
programme. But first this is
something that isn't in the users
manual. Comes from a book that
teaches making text adventure games.
Put the DIM ARRAYS at the start or as
close to the start of your programme
as possible. That Commodore users
guide uses several dim arrays for the
games. These are all "declared" in
the first several lines of the
programme. Though defined a bit later
in the programme.
An example from a programme that I
modified. No it isn't really that
impressive, remember I am a lamer at
this stuff. I just used some of the
things that we have or will cover in
this users manual. Well the program
is one that I saved from Q-Link. Done
in Basic and it for the creation of
1st edition of Advanced Dungeons &
Dragons monsters. Saved it to disk
and printed it out. I did a few
things to it, such as adding some
stats. Those where different
variables, and we covered them
already. What I did that applies to
this part of the series, is that I
created a Dim Array. Originally,
after you typed in the stats for the
monster for your game. You could
write a description. However the
author made a one dimensional array.
Meaning that I had only 11 lines max
for a description of the monster and
its habits. Not enough when I am
copying them out of old and crumbling
magazines that are over 25 years old.
What I did was simply turn that into
a Dim Array looking like DIM C(40). C
being the existing variable. Now I
have many more lines for a
description. See it isn't that
fantastic. Just a simple re-write of
one line. Oh yeah that was in the
first 15 or so lines of
programming/code.
new
1 rem dice simulation:?"<shift
clearhome>"
10 input"how many rolls:";x
20 forl=1tox
30 r=int(6*rnd(1))+1
40 f(r)=f(r)+1
50 nextl
60 ?"face","number of times"
70 forc=1to6:?c,f(c):next
Running this and you will get a list
on the left of the faces of a D6 <6
sided die> and the number of times
that face appeared out of the total
number of times that you entered for
the number of rolls. F(R) is the
array for the random number generator
in line 30. L is the variable for the
number of times the die is to be
rolled. Line 70 has the C= 1 to 6
Then it wants the value of C printed.
The faces on the left of the screen.
But see that next there is the array
of F(C). Bit confusing as the
explanation in the Commodore users
guide is short and lacking in depth.
My understanding, and it is quite
possibly wrong, is that the F(R) is
the array for the number of times and
the F(C) is the array for that number
for each face or side of the die.
They next turn the page to 100 and
show the same programme using IF THEN
statements. Doubles in the number of
lines used. More than double in the
space in the computer that would be
used.
TWO-DIMENSIONAL ARRAYS is the title
for the next part. They start off
with showing us what it would look
like Z(4,6) is a two dimensional
array. First part is the array name
and the other two parts separated by
the, symbol are the subscripts.
Written out in a matrix type box with
the following value of Z(3,4)=71would
look like the following in the above
defined two dim array.
0 1 2 3 4 5 6
0 - - - - - - -
1 - - - - - - -
2 - - - - - - -
3 - - - - 71 - -
First subscript is sort of the row
and the second one is sort of the
column. You can get the idea that
there can now be a lot more installed
than before. OK there are some rules
to follow in creating a two dim
array.
Gotta dim the array: dimZ(4,6) as
the first part. That sets up the
areas for use. Next you need to
assign the data that is going into
the array sort of like: Z(3,4)=71.
Next assign the values to other
variables like: ZB=Z(1,1). Then print
the values. Complex, confusing it
doth sound at this point. Trust me
that I dig that part, no not the
variable thing, that it is complex
and confusing. This is not something
you can get in one sitting. Takes
several goings over, and other
sources of information to slowly
click. Then you ask yourself why you
didn't catch it at the start, since
it is so simple. Or so I have been
told. I'm still at the part of the
light is just turning on for these
arrays. My advice is to just ride
this part for now. Work on the ideas
as you feel comfortable. Now then
lets move onto a type in example.
new
20 ?"<shifted clear home>"
30 forr=1to4
40 ?"Question # : ";r
50 ?" 1-yes 2-no 3-undecided"
60 ?"what was the response : ";
61 getc:ifc,1orc>3then61
65 ?c:?
70 a(r,c)=a(r,c)+1
80 nextr
85 ?
90 ?"do you want to enter
another":?"response (y/n)";
100 geta$:ifa$=22then100
110 ifa$="y"then20
120 ifa$<>"n"then100
130 ?"<sifted clear home>";"the total
responses were:":?
140 ?spc(18);"responce"
141
?"question","yes","no","undecided"
142 ?"--------
-----------------------------"
150 ?r=1to4
160 ?r,a(r,1),a(r,2),a(r,3)
170 nextr
Give it a run and see what happens.
You end up with 4 questions. Well not
exactly, since they are never stated
as what is the question. Then you
have a choice of one out of 3 for a
reply to each of the 4. This is going
to be tabulated at the end with how
many times each of the possible three
answers were given for each of the 4
questions. Line 142 is a bit of a
problem in getting the - lines
correct. Don't worry if you flubbed
that one. I always do myself. Line
140 has a spc(18). That takes the
writing to the 18th space on the row.
Those comma things in line 141, space
out by 10 remember. Making columns
for the final print out on the
screen. 100-120 is our simple get a
reply from the kb. In fact most of
this we have seen and done in some
form already.
The Commodore users guide covers this
entire programme in three paragraphs,
and that is on one page, with a
quarter of the page blank and a chart
at the top of the page. Right; not a
lot of data for you to read and learn
how this all works. That is something
I was recently talking about on the
some IRC chats, how it is easier to
learn with others than by yourself,
and the lack of in-depth information
in the user's manual. Before the
comments though, lets look at the
array stuff in this programme.
Really the array stuff is the new
part. We see an array at line 70. BTW
that will update the element. So says
the rem statement on that line in the
Commodore users guide. What type of
array is it? That is a bit harder to
see. A(R,C) this tells us it is a two
dimensional array. Because of the two
elements inside. But now then, what
are the parameters of these elements?
That takes a little bit of looking at
the programme. In the array of A(R,C)
we look through the programme and see
that the R is in line 30, and is for
the number of questions. There are 4
questions or 4 elements. That makes
the R=4, so A(4,C) is what we have so
far. Line 61 sets up the ends for C
being 1-3. OK that must be the yes
and no and undecided part. Line 65
prints c. C then is 3 and that means
our array of A(R,C) is A(4,3). Right
a 4 by 3 two dimensional array. At
this point it is important to know
that the first row and column of
A(0,0), or the first row and column
of any array is mainly never used. So
is the impression from the Commodore
users guide. Line 160 prints the
values, the values of the elements in
A(R,1) A(R,2) and A(R,3) The numbers
for the yes, no and undecided. Yeah
it is confusing and complicated at
the start. I honestly at this time am
still learning this section.
Outro will have some more statements
on this part. Last of the Commodore
users guide now. Appendices and these
are a list of accessories for the 64,
Advanced Cassette Operation, Basic
term explanation, Key abbreviations,
Screen Codes, Ascii & CHR$ codes,
Memory Maps, Math functions,
Printouts, Programmes to try out,
Basic conversion, Error Message,
Musical notes, and if you have a copy
and are lucky. There is a quick
reference card at the end. May you
find a copy and with this series,
have some fun in programming.
COMMODORE FREE
I tried to put the Commodore Users
Guide into the Loadstar Quick menu,
you can download a copy from the
website www.commodorefree.com
Because of the size I had to split the
manual into 2 d64 images:
http://www.commodorefree.com/
tools/guide/guide1.zip
http://www.commodorefree.com/
tools/guide/guide2.zip
The text is taken from Project 64
version of the user guide in plain
text so many of the diagrams are
converted to text art.
END